#![allow(dead_code)]
pub struct Solution;

impl Solution {
    pub fn move_zeros(nums: &mut Vec<i32>) {
        let mut copyto: usize = 0;

        for nz in 1..nums.len() {
            if nums[nz] != 0 {
                nums[copyto] = nums[nz];
                copyto += 1;
            }
        }
        for z in copyto..nums.len() {
            nums[z] = 0;
        }
    }

    pub fn add_one(mut nums: Vec<i32>) -> Vec<i32> {
        for num in nums.iter_mut().rev() {
            if *num != 9 {
                *num += 1;
                return nums;
            }
            *num = 0;
        }
        nums.insert(0, 1);
        nums
    }

    pub fn remove_duplicates(mut nums: Vec<i32>) -> Vec<i32> {
        if nums.len() == 0 {
            return nums;
        }

        let mut slow: usize = 0;
        for fast in 1..nums.len() {
            if nums[slow] != nums[fast] {
                if fast - slow > 1 {
                    slow += 1;
                    nums[slow] = nums[fast];
                }
            }
        }
        for _ in slow..nums.len() - 1 {
            nums.remove(slow + 1);
        }
        nums
    }
}

pub fn test_array() {
    println!("\n========== 移动零 ===========");
    let mut nums: Vec<i32> = vec![0, 1, 0, 3, 12];
    println!("nums: {:?}", nums);
    Solution::move_zeros(&mut nums);
    println!("移动零后: {:?}", nums);

    println!("\n========== 加一 ===========");
    let nums: Vec<i32> = vec![1, 2, 3];
    println!("nums: {:?}", nums);
    println!("加1: {:?}", Solution::add_one(nums));
    let nums: Vec<i32> = vec![9, 9, 9];
    println!("nums: {:?}", nums);
    println!("加1: {:?}", Solution::add_one(nums));

    println!("\n========== 删除重复元素 ===========");
    let nums: Vec<i32> = vec![0, 0, 1, 1, 1, 2, 2, 3, 3, 4];
    println!("nums: {:?}", nums);
    println!("删除重复元素: {:?}", Solution::remove_duplicates(nums));
}
